<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/table.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
</head>
<body>
<div class="layui-row layui-col-space10" style="background-color: #F2F2F2;">
    <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
        <div class="layui-card">
            <div class="layui-card-body">
                <header style="height: 100%">
                    <div align="left">
                        <table style="width: 100%">
                            <tr>
                                <td>
                                    <form id="form" class="form-inline" method="post" action="/goods/export" enctype="multipart/form-data">
                                        <div class="form-group">
                                            编码：<input id="code" name="code" type="text" class="form-control" placeholder="商品编号">
                                            商品名称：<input id="name" name="name" type="text" class="form-control" placeholder="商品名称">
                                        </div>
                                    </form>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <button id="searchBt" class="layui-btn layui-btn-sm search"><i class="layui-icon">&#xe615;</i>搜索</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </header>
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                            <tr>
                            </tr>
                            <tr>
                                <th>ID</th>
                                <th>商品名称</th>
                                <th>编码</th>
                                <th>分类</th>
                                <th>规格</th>
                                <th>单位</th>
                                <th>单价</th>
                                <th>是否常规物料</th>
                                <th>是否耗材</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3" style="height: 100%;">
        <div class="layui-card">
            <div class="layui-card-header">选中项</div>
            <div class="layui-card-body">
                <ul id="selectedItems"></ul>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    layui.use('layer', function(){
        var layer = layui.layer;
    });

    var pers = checkPermission();

    const isMultiSelect = eval(getUrlParam("isMultiSelect"));

    var example;
    function init(){
        example =
            $('#dt-table').DataTable({
                "displayLength" : 10,
                "scrollY": "calc(100vh - 150px)",
                "searching": false,
                "processing": true,
                "serverSide": true,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/goods/list",
                    "type": "get",
                    "data": function (d) {
                        d.code = $('#code').val().trim();
                        d.name = $('#name').val().trim();
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-4 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-8' p v>>",
                "columns": [
                    {"data": "id", "defaultContent": "", "visible": true},
                    {"data": "name", "defaultContent": ""},
                    {"data": "code", "defaultContent": ""},
                    {"data": "categoryName", "defaultContent": ""},
                    {"data": "specification", "defaultContent": ""},
                    {"data": "unit", "defaultContent": ""},
                    {"data": "unitPrice", "defaultContent": ""},
                    {
                        "data": "isCommon",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return getDict('boolean')[data];
                        }
                    },
                    {
                        "data": "isConsumables",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return getDict('boolean')[data];
                        }
                    },
                ],
                "initComplete": function(settings, json) {

                },
                "rowCallback": function (row, data) {
                    $(row).on('click', function () {
                        if ($(this).hasClass('success')) {
                            $(this).removeClass('success');
                        } else {
                            if (!isMultiSelect) {
                                example.$('tr.success').removeClass('success');
                            }
                            $(this).addClass('success');
                        }
                        addItem(data, 'name', isMultiSelect);
                    })
                },
                "order": [[0, "asc"]]
            });
    }

    $("#searchBt").click(function(){
        example.ajax.reload();
    });

    // 导出
    function download() {
        $("#form").submit();
    }

    init();
</script>
